package com.useeinfo.oa.modules.inspection.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.base.entity.FacilityCat;
import com.useeinfo.oa.modules.base.entity.Organization;

import javax.persistence.*;

/**
 * 巡检工艺表
 */
@Entity
@Table(name = "inspection_technology")
public class InspectionTechnology extends SuperClassEntity<InspectionTechnology> {
    /**
     * 流水号
     */
    private String code;
    /**
     * 名称
     */
    private String name;
    /**
     * 所属类型
     */
    @ManyToOne
    @JoinColumn(name = "facilityCat_Id")
    private FacilityCat facilityCat;
    /**
     * 所属部门
     */
    @ManyToOne
    @JoinColumn(name = "organization_id")
    private Organization organization;
    /**
     * 预计工时(分钟)
     */
    private String estimateTime;
    /**
     * 要求技能
     */
    private String requireSkill;
    /**
     * 是否有效
     */
    @Column(columnDefinition = "bit default 0")
    private boolean effective;
    /**
     * 详细说明
     */
    @Column(columnDefinition="text")
    private String description;
    /**
     * 巡检内容快照
     */
    @Column(columnDefinition="text")
    private String inspectionDataContent;

    /**
     * 所属企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public FacilityCat getFacilityCat() {
        return facilityCat;
    }

    public void setFacilityCat(FacilityCat facilityCat) {
        this.facilityCat = facilityCat;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public String getEstimateTime() {
        return estimateTime;
    }

    public void setEstimateTime(String estimateTime) {
        this.estimateTime = estimateTime;
    }

    public String getRequireSkill() {
        return requireSkill;
    }

    public void setRequireSkill(String requireSkill) {
        this.requireSkill = requireSkill;
    }

    public boolean isEffective() {
        return effective;
    }

    public void setEffective(boolean effective) {
        this.effective = effective;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getInspectionDataContent() {
        return inspectionDataContent;
    }

    public void setInspectionDataContent(String inspectionDataContent) {
        this.inspectionDataContent = inspectionDataContent;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("name", StringConverters.null2String(getName()));
        jsonObject.put("code", StringConverters.null2String(getCode()));
        jsonObject.put("estimateTime", StringConverters.null2String(getEstimateTime()));
        jsonObject.put("requireSkill", StringConverters.null2String(getRequireSkill()));
        jsonObject.put("effective", isEffective());
        jsonObject.put("facilityCatName", getFacilityCat() == null ? "" : getFacilityCat().getCatName());
        jsonObject.put("facilityCatId", getFacilityCat() == null ? null : getFacilityCat().getId());
        if(getEnterprise()!=null){
            jsonObject.put("enterpriseName", StringConverters.null2String(getEnterprise().getEnterpriseName()));
        }else{
            jsonObject.put("enterpriseName", "");
        }
        if(getOrganization()!=null){
            jsonObject.put("organizationName", StringConverters.null2String(getOrganization().getOrganizationName()));
        }else{
            jsonObject.put("organizationName", "");
        }
        return jsonObject;
    }
}
